
var app=getApp();

var baseurl = "https://api2.nahuo.com/test/buyertool/";
var httppost = function (url, params, doComplete, method) {
  var realurl = baseurl + url;
  var str = "";
  app.showLoading("");
  wx.request({
    url: realurl,
    data: params,
    method: method,
    
    success: function (res) {
    
        if (res.data.Result) {
        if (typeof doComplete == "function") {

          
          doComplete(res.data.Data);
        }
      } else {
        wx.showToast({
          title: res.data.Message,
          icon: 'success'
        })
      }

    },
    fail: function (res) {
      wx.showToast({
        title: "网络出错了",
        icon: 'success',
        mask: true
      })
    }

  });
}

var httppostmore = function (url, params, doComplete, method) {
    var realurl = baseurl + url;
    var str = "";
    app.showLoading("");
    wx.request({
        url: realurl,
        data: params,
        method: method,

        success: function (res) {


            if (res.data.Result) {
                if (typeof doComplete == "function") {


                    doComplete(res.data);
                }
            } else {
                wx.showToast({
                    title: res.data.Message,
                    icon: 'success'
                })
            }

        },
        fail: function (res) {
            wx.showToast({
                title: "网络出错了",
                icon: 'success',
                mask: true
            })
        }

    });
}

//json输出
function json2Form(json) {
  var str = [];
  for (var p in json) {
    str.push(encodeURIComponent(p) + "=" + encodeURIComponent(json[p]));
  }
  return str.join("&");
}

//模块输出
module.exports = {
  httppost: httppost,
  httppostmore: httppostmore

}